<template>
  <div class="newpage">
    <div class="content">
      <el-form ref="form" :model="formInline" label-width="80px">
        <div class="topBox">
          <div class="first">
            <div class="collegeName">
              <span>学院名称</span>
              <el-select v-model="formInline.colleageName" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.index"
                  :label="item.colleageName"
                  :value="item.colleageName"
                >
                </el-option>
              </el-select>
            </div>
            <div class="createTime">
              <div class="block">
               <el-form-item label="日期">
                         <el-date-picker
                            v-model="formInline.beginTime"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd"
                            >
                        </el-date-picker>
                        -
                        <el-date-picker
                            v-model="formInline.endTime"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd"
                            >
                        </el-date-picker>
                    </el-form-item>
              </div>
            </div>
          </div>
          <div class="second">
            <div class="collegeName">
              <span>所属区域</span>
              <el-input  v-model="formInline.site" placeholder="请输入详细地址"></el-input>
            </div>
            <div class="createTime">
              <span>描述</span>
              <el-input v-model="formInline.describeText" type="textarea"></el-input>
            </div>
          </div>
          <div class="plannedEnrollment">
            <span>计划招生人数</span>
            <ul>
              <li v-for="(item, index) in formInline.admissionSchemeNumber" :key="index">
                <span class="number"></span>

            <div class="countInp">
              <el-select ref='select' v-model="item.majorId"  placeholder="请选择专业" @change="change($event)">
                <el-option v-for="item in major"
                 :key="item.index" :label="item.majorName" :value="item.majorId">
                </el-option>
              </el-select>
                </div>
                <span class="counts">招生人数</span>
                <div class="countInp">
                  <el-input  v-model="item.studentNumber" placeholder=""></el-input>
                </div>
                <i class="el-icon-remove-outline"></i>
              </li>
              <el-button icon="el-icon-plus" @click="addOut">添加</el-button>
            </ul>
          </div>
        </div>
        <div class="btn">
          <el-button @click="out">取消</el-button>
          <el-button @click="add">确定</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import {
  majorListApi,
} from "@/api/basics/major";
import {
  getTableApi,
} from "@/api/basics/college.js"
import {recruitAdd} from '@/api/recruitStudents/recruit.js'
export default {
  data() {
    return {
      provinceList:[],
      formInline: {
        beginTime:'',
        endTime:'',
        site:'',
        colleageName:'',
        admissionSchemeNumber:[],
        describeText:'',
      },
        options: [],
        major:'',
      input: '',
    }
  },
   mounted() {
    this.getTableListApi()
    this.getmajor()
  },
  methods: {
    async getmajor(){
      let res=await majorListApi()
      this.major=res.rows
      console.log('44',res)
      console.log('33333',this.major)
    },
    async getTableListApi() {
      let res = await getTableApi();
      console.log("222", res);
      this.options = res.rows;
    },
    //添加
   async add(){
       let res=await recruitAdd(this.formInline)
       console.log(res)
       this.$message.success("添加成功");
       this.$router.push('/recruitstudents/Enrollmentplan')
    },
    change(label){
      console.log(label);
    },
    //取消
    out(){
this.$router.push('/recruitstudents/Enrollmentplan')
    },
  // 初始化地址
     addOut() {
      this.formInline.admissionSchemeNumber.push({majorId:this.major,studentNumber:''});
    },
    onSubmit() {
      console.log("submit!");
    },
  },
};
</script>

<style lang="scss" scoped>
.newpage {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0 20px 20px;
  display: flex;
  // flex-direction: column;

  .content {
    flex: 1;
    background-color: white;
    border-radius: 10px 10px;
    min-width: 150vh;

    .topBox {
      padding: 60px;

      span {
        display: block;
        font-size: 14px;
      }

      .createTime {
        margin-left: 90px;
      }

      .first {
        .collegeName,
        .createTime {
          display: inline-block;
        }

        .block {
          display: inline-block;
        }
      }

      .second {
        margin-top: 30px;

        .collegeName,
        .createTime {
          vertical-align: top;
          display: inline-block;
        }
      }

      .plannedEnrollment {
        ul {
          // width: 100%;

          li {
            display: inline-block;
            width: 45%;
            margin: 10px 0;

            ::v-deep .el-input__inner {
              height: 26px;
            }

            ::v-deep .el-input__icon {
              line-height: 30px;
            }

            .number {
              margin: 0 15px;
              border: none;
            }

            .counts {
              // width: 50px;
              margin: 0 10px;
            }

            .countInp {
              display: inline-block;

              ::v-deep .el-input {
                width: 90px;
              }
            }

            i {
              margin-left: 10px;
              color: #ccc;
              font-size: 18px;
            }
          }
        }

        span {
          display: inline-block;
          margin: 25px 0 15px 5px;
        }

        .el-button {
          width: 400px;
          height: 36px;
          /* line-height: 30px; */
          border: 1px dashed #ccc;
          margin-left: 35px;
          text-align: center;
        }
      }
    }

    .btn {
      width: 400px;
      text-align: center;
      margin-left: 30px;
      margin-bottom: 30px;

      .el-button {
        margin-left: 30px;
      }
    }
  }
}
</style>
